<template>
	<view>
		<!-- search 搜索框 -->
		<view class="search-box">
			<my-search bgcolor="#C00000" redius="18"></my-search>
		</view>
		
	   <!-- 轮播图区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
		  <!-- 循环渲染轮播图的 item 项 -->
		  <swiper-item v-for="(item, i) in swiperList" :key="i">
			<navigator :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id"  class="swiper-item">
			  <!-- 动态绑定图片的 src 属性 -->
			  <image :src="item.image_src"></image>
			</navigator>
		  </swiper-item>
		</swiper>
		
		<!-- 分类导航 -->
		<view class="nav-list">
		   <view class="nav-item" v-for="(item, i) in navList" :key="i" @click="navClickHandler(item)">
		     <image :src="item.image_src" class="nav-img"></image>
		   </view>
		</view>
		
		<!-- 楼层标题区 -->
		<view class="floor_list">
			<view class="floor_item" v-for="(item,i) in floorList" :key="i">
				<image :src="item.floor_title.image_src"  class="floor_title"></image>
				<!-- 楼层图片区 -->
				<view class="floor_img_box">
					<!-- 左侧图片 1张 -->
					<view class="left_img_box" @click="goGoodsList(item.product_list[0])">
						<image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
					</view>
					<!-- 右侧图片 4 张 -->
					<view class="right_img_box">
						<view v-for="(v,i) in item.product_list" :key="i" @click="goGoodsList(v)">
							<image :src="v.image_src" :style="{width:v.image_width+'rpx'}" mode="widthFix" v-if="i!=0"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>item.

<script>
	export default {
		data() {
			return {
				navList: [],//分类导航数据
				swiperList:[],
				floorList:[]//楼层数据
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getnavList()
			this.getfloorList()
		},
		methods:{
			async getfloorList(){
				 const {data:res} = await uni.$http.get('/api/public/v1/home/floordata')
				 if(res.meta.status !=200){
				 	 uni.$showMsg()
				 }
				 res.message.forEach((floor,index)=>{
					  floor.product_list.forEach((item)=>{
						   item.url = '/subpkg/goods_list/goods_list?'+item.navigator_url.split('?')[1]
					  })
				 })
				 this.floorList = res.message
			},
			async getSwiperList(){               
			     const{data:res} = await uni.$http.get('/api/public/v1/home/swiperdata');
				 if(res.meta.status !=200){
					uni.$showMsg()
				 }
				 this.swiperList = res.message
			},
			async getnavList(){
				const {data:res} = await uni.$http.get('/api/public/v1/home/catitems');
				if(res.meta.status !=200){
					uni.$showMsg()
				}
				this.navList = res.message
			},
			navClickHandler(item){
				console.log(uni,'ni')
				 if(item.name ==='分类'){
					 uni.switchTab({
					 	url:'/pages/cate/cate'
					 })
				 }
			},
			goGoodsList(item){
			     uni.navigateTo({
			     	 url:item.url
			     })
			}
		}
	}
</script>

<style lang="scss">
swiper{
	height:300rpx;
	.swiper-item,image{
			height:100%;
			width:100%;
		}
}

.nav-list {
  display: flex;
  justify-content: space-around;
  margin: 15rpx 0;

  .nav-img {
    width: 128rpx;
    height: 140rpx;
  }
}
.floor_title{
	height:60rpx;
	width: 100%;
	// display:flex;
}

.right_img_box{
		display:flex;
		flex-wrap:wrap;
		justify-content:space-around;
	}
	.floor_img_box{
		display:flex;
		padding-left: 10rpx;
	}
	.search-box{
		position:sticky;
		top:0px;
		z-index:999
	}
</style>
